//
//  SISSPassengerCooperationProgressManageCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/19.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSPassengerCooperationProgressManageCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSPassengerCooperationProgressManageCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *agencyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *markLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyerNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaHouseTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *progressTagLabel;
@property (weak, nonatomic) IBOutlet UIButton *redDotButton;

@end
@implementation 
SISSPassengerCooperationProgressManageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.markLabel.layer.borderWidth = 1;
    
    self.markLabel.layer.borderColor = COLOR(0x8998A5).CGColor;
    self.markLabel.layer.cornerRadius = 2;
    self.markLabel.layer.masksToBounds = YES;
}

- (void)setPassengerCoopProgressModel:(SISSPassengerCoopProgressModel *)passengerCoopProgressModel {
    _passengerCoopProgressModel = passengerCoopProgressModel;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:passengerCoopProgressModel.portrait] placeholderImage:[UIImage imageNamed:@"头像"]];
    self.agencyNameLabel.text = passengerCoopProgressModel.name;
    self.companyLabel.text = passengerCoopProgressModel.organ_name;
    // 根据身份证判断显示 先生、女士
    NSString *fisrtName = [passengerCoopProgressModel.buyer_name substringToIndex:1];
    NSInteger idNum = [[passengerCoopProgressModel.idNo substringWithRange:NSMakeRange(passengerCoopProgressModel.idNo.length - 2, 1)] integerValue];
    NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
    self.buyerNameLabel.text = [NSString stringWithFormat:@"%@%@",fisrtName,genderStr];
    
    self.markLabel.text = passengerCoopProgressModel.type == 2 ? @" 发布方 " : @" 合作方 ";
    
    self.regionAreaHouseTypeLabel.text = [NSString stringWithFormat:@"%0.f-%0.f万 | %@-%@ | %@",passengerCoopProgressModel.minPrice,passengerCoopProgressModel.maxPrice,passengerCoopProgressModel.region,passengerCoopProgressModel.regionDetail,passengerCoopProgressModel.houseType];
    NSArray *progressArr = @[ @"上传合作协议", @"实地看房", @"上传居间合同", @"上买卖合同", @"服务评价", @"已完成"];
    self.redDotButton.hidden = !passengerCoopProgressModel.has_news;
    NSInteger count = self.isHistory ? 2 : 1;
    if (passengerCoopProgressModel.progress == 6) {
        count = 1;
    }
    self.progressTagLabel.text = progressArr[passengerCoopProgressModel.progress - count];
}

/**
 咨询按钮点击事件
 */
- (IBAction)contactButtonClickAction:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(passengerCooperationProgressManageCell:clickContactButton:)]) {
        [self.delegate passengerCooperationProgressManageCell:self clickContactButton:sender];
    }
}

@end
